package com.aaa.ssm.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//@WebFilter(filterName = "loginFilter",value = "/*")
public class LoginFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request1 = (HttpServletRequest) request;
        HttpServletResponse response1 = (HttpServletResponse) response;
        String requestURI = request1.getRequestURI();
        System.out.println("所有请求："+requestURI);
        if (requestURI.endsWith(".css") ||requestURI.endsWith(".js")
                ||requestURI.endsWith(".jpg") ||requestURI.contains("/tuser/add")
                || requestURI.contains("/login.html")|| requestURI.contains("/t-login.html")
                || requestURI.contains("/zclogin.html")|| requestURI.contains("/login")) {
            chain.doFilter(request1, response1);
        } else {
            Object loginA = request1.getSession().getAttribute("loginA");
            System.out.println(loginA);
            System.out.println("loginA----------------------------------------："+loginA);
            if (loginA == null) {
                response1.sendRedirect("/html/front/t-login.html");
            }else {
                chain.doFilter(request1, response1);
            }
        }

    }

}